using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

using Material.Object;
using Material.Entity;


namespace Material.App
{
    public partial class FrmInqueryPiutang : Form
    {
        private TblTransHutangHDREntity  tblTransHutangHDREntity;
        private string connStr = ConfigurationManager.ConnectionStrings["dbconnection"].ToString();
        public string idBarang = string.Empty;

        public FrmInqueryPiutang()
        {
            InitializeComponent();
            BindGrid();
            cbListParameter.SelectedIndex = 0;

            dataGridView1.RowsDefaultCellStyle.BackColor = Color.Bisque;
            dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige;
            dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;

            dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Green;
            dataGridView1.DefaultCellStyle.SelectionForeColor = Color.Yellow;

            //dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
            //dataGridView1.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;

            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            //dataGridView1.AllowUserToResizeColumns = false;
        }

        private void FrmFindBarang_Load(object sender, EventArgs e)
        {

        }

        private void BindGrid()
        {
            tblTransHutangHDREntity = new TblTransHutangHDREntity(connStr);
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = tblTransHutangHDREntity.GetDataFindAll().Tables[0];
        }

        private void BindGrid(string parameter,string value)
        {
            tblTransHutangHDREntity = new TblTransHutangHDREntity(connStr);
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = tblTransHutangHDREntity.GetDataFindAll(parameter, value).Tables[0];
        }

        private void cbListParameter_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtFind.Text = string.Empty;
            if (cbListParameter.SelectedIndex == 0)
            {
                txtFind.Visible = false;
                btnFind.Visible = false;
                cbListFind.Visible = false;
                
                tglAkhir.Visible = false;
                tglMulai.Visible = false;
                lblTgl.Visible = false;
                BindGrid();
            }
            else if (cbListParameter.SelectedIndex == 1)
            {
                //cbListFind.Visible = true;
                txtFind.Visible = true;
                btnFind.Visible = true;
                cbListFind.Visible = false;
                tglAkhir.Visible = false;
                tglMulai.Visible = false;
                lblTgl.Visible = false;

                txtFind.Focus();
            }
            else if (cbListParameter.SelectedIndex == 2)
            {
                txtFind.Visible = true;
                btnFind.Visible = true;
                cbListFind.Visible = false;
                tglAkhir.Visible = false;
                tglMulai.Visible = false;
                lblTgl.Visible = false;

                txtFind.Focus();
            }
            else if (cbListParameter.SelectedIndex == 3)
            {
                cbListFind.Visible = true;
                txtFind.Visible = false;
                btnFind.Visible = true;

                tglAkhir.Visible = false;
                tglMulai.Visible = false;
                lblTgl.Visible = false;


                cbListFind.SelectedIndex = 0;

            }
            else if (cbListParameter.SelectedIndex == 4)
            {
                tglAkhir.Visible = true;
                tglMulai.Visible = true;
                lblTgl.Visible = true;

                cbListFind.Visible = false;
                txtFind.Visible = false;
                btnFind.Visible = true;

            }

            else if (cbListParameter.SelectedIndex == 5)
            {
                tglAkhir.Visible = true;
                tglMulai.Visible = true;
                lblTgl.Visible = true;

                cbListFind.Visible = false;
                txtFind.Visible = false;
                btnFind.Visible = true;

            }
            
        }

        private void btnFind_Click(object sender, EventArgs e)
        {
            if (cbListParameter.SelectedIndex == 1)
            {
                if (txtFind.Text.Trim().Length == 0)
                {
                    MessageBox.Show("Parameter pencarian harus diisi..","Pesan",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                    return;
                }
                else
                {
                    BindGrid("Nama",txtFind.Text.Trim());
                }
            }

            else if (cbListParameter.SelectedIndex == 2)
                BindGrid("Alamat",txtFind.Text);

            else if (cbListParameter.SelectedIndex == 3)
            {
                
                BindGrid("StatusHutang", cbListFind.SelectedIndex.ToString());
            }

           else if (cbListParameter.SelectedIndex ==4)
                BindGrid("TglHutang", tglMulai.Value.ToString("dd/MM/yyy") + "|" + tglAkhir.Value.ToString("dd/MM/yyyy"));

            else if (cbListParameter.SelectedIndex == 4)
                BindGrid("TglLunas", tglMulai.Value.ToString("dd/MM/yyy") + "|" + tglAkhir.Value.ToString("dd/MM/yyyy"));


        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {
            
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if ((e.RowIndex > -1) && (e.ColumnIndex > -1))
            {

                switch (e.ColumnIndex)
                {
                    case 1:
                        FrmPiutangDetail.IdTransHDR = Convert.ToInt16(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
                        FrmPiutangDetail frm = new FrmPiutangDetail();
                        
                        frm.ShowDialog();
                        break;
                }
            }
        }


    }
}